<style lang="less">
    @import './login.less';
</style>

<template>
    <section class="login">
        <div class="login_left"></div>
        <div class="login_right">
            <!--登陆模块-->
            <login-form v-if="status=='login'" ref="loginForm" @on-login="handleSubmit"
                        @on-forget="status='login_forget'"
                        @on-register="status='login_register'"
                        :user="user"></login-form>
        </div>
    </section>
</template>

<script>

import LoginForm from './components/login-form'
import { mapActions } from 'vuex'

export default {
    name: 'login',
    data(){
        return {
            status: 'login',
            user: {},
        }
    },
    components: {
        LoginForm
    },
    mounted: function (){
        if(this.$route.query.token){
            this.status = 2;
        }
    },
    methods: {
        ...mapActions([
          'handleLogin',
          'getUserInfo'
        ]),
        //登陆
        handleSubmit ({ username, password, remember}) {
            var self = this;
            this.handleLogin({ username, password, remember, self }).then( isLogin => {
                this.$refs.loginForm.loginLoading = false;
                if(!isLogin){
                    return;
                }
                this.getUserInfo(self).then(res => {
                    this.$router.push({name: this.$config.homeName})
                });
            });
        },
        handleRegisterSubmit(user) {
            this.status = 'login';
            this.user = user;
        },
    }
}
</script>
<style>

</style>
